﻿// -----------------------------------------------------------------------------
// 园丁,是个很简单的管理系统
//  gitee:https://gitee.com/hgflydream/Gardener 
//  issues:https://gitee.com/hgflydream/Gardener/issues 
// -----------------------------------------------------------------------------

using Gardener.Core.Client.Authorization;
using Microsoft.AspNetCore.Components;

namespace Gardener.Weighbridge.Client.Pages.WeighingRecordView
{
    /// <summary>
    /// WeighingRecord编辑页
    /// </summary>
    public partial class WeighingRecordEdit : EditOperationDialogBase<WeighingRecordDto, Guid, WeighbridgeLocalResource>
    {
        private List<WeighbridgeConfigDto> weighbridgeConfigs = [];
        private List<CommodityDto> commodityConfigs = [];

        [Inject]
        private IWeighbridgeConfigService weighbridgeConfigService { get; set; } = default!;
        [Inject]
        private ICommodityService commodityService { get; set; } = default!;
        [Inject]
        private IAuthenticationStateManager authenticationStateManager { get; set; } = default!;
        /// <summary>
        /// 页面初始化后
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override async Task OnDataLoadingAsync()
        {
            weighbridgeConfigs = await weighbridgeConfigService.GetAllUsable();
            commodityConfigs = await commodityService.GetAllUsable();
            await base.OnDataLoadingAsync();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commodity"></param>
        /// <returns></returns>
        private string FormatCommodityLable(CommodityDto commodity)
        {
            return $"{commodity.CommodityName}({commodity.CommodityCode})";
        }
        /// <summary>
        /// 选择商品
        /// </summary>
        /// <param name="commodity"></param>
        private void OnSelectedItemChangedCommodity(CommodityDto commodity)
        {
            _editModel.CommodityName = commodity.CommodityName;
        }
        protected override Task<bool> OnVerificationBefor()
        {
            _editModel.OperatorName = authenticationStateManager.GetCurrentUser()?.NickName ?? string.Empty;
            return base.OnVerificationBefor();
        }
    }
}
